<?php

namespace app\common\model;

use think\db\Query;

/**
 * Class LawCaseCategory
 * @package app\model
 * @property int $id
 * @property int $userId
 * @property string $name
 * @property int $ord
 * @property string $remarks
 * @property string $smallPic
 * @property int $updated
 * @property int $created
 * @method $this shortCategory()
 * @link https://www.kancloud.cn/manual/thinkphp6_0/1037579
 * @link https://www.kancloud.cn/manual/think-orm/1257998
 * @link https://www.kancloud.cn/thinkphp/master-database-and-model/265551
 */
class LawCaseCategory extends \app\common\model\BaseModel
{
    protected $name = 'LawCaseCategory';

    public function scopeShortCategory(Query $query)
    {
        $query->field(['id', 'name'])->hidden(['pivot']);
    }

    public function professionalQas()
    {
        return $this->hasMany(Consulting::class, 'categoryId', 'id');
    }

    public function getSmallPicImgAttr($value, $data)
    {
        return image_url($data['smallPic'] ?? '');
    }

    public function getSmallPicImgMinAttr($value, $data)
    {
        return image_url($data['smallPic'] ?? '', 'min');
    }

    /**
     * 1对1
     * @return \think\model\relation\HasOne
     */
    //    public function one(){
    //        return $this->hasOne( Test1::class, 'Test1表中的键', 'LawCaseCategory表中的键');
    //    }

    /**
     * 1对多
     * @return \think\model\relation\HasMany
     */
    //    public function many(){
    //        return $this->hasMany( Test1::class, 'Test1表中的键', 'LawCaseCategory表中的键');
    //    }

    /**
     * 多对多
     * @return \think\model\relation\BelongsToMany
     */
    //    public function belongs(){
    //        return $this->belongsToMany( Test1::class, '中间表', '中间表中Test1的键', '中间表中LawCaseCategory的键');
    //    }
}
